//
//  ViewController.m
//  lzl5-31
//
//  Created by 刘振霖 on 16/5/31.
//  Copyright © 2016年 lzl. All rights reserved.
//

#import "ViewController.h"

#import "TwoViewController.h"
#import "EditViewController.h"

@interface ViewController () <EditDelegate>

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
    self.navigationItem.title = @"我的导航标题";
    self.view.backgroundColor = [UIColor redColor];
    self.refreshControl = [UIRefreshControl new];
    self.refreshControl.tintColor = [UIColor greenColor];
    self.refreshControl.attributedTitle = [[NSAttributedString alloc] initWithString:@"看我刷新" attributes:@{NSForegroundColorAttributeName:[UIColor greenColor]}];
    self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"5"] style:UIBarButtonItemStylePlain target:self action:@selector(onClick:)];
    UIImageView *iv = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"4"]];
    self.navigationItem.titleView = iv;
}

- (void)onClick:(id)sender
{
    [self.refreshControl endRefreshing];
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return 4;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    UITableViewCell *cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:nil];
    NSString *imgName = [NSString stringWithFormat:@"%ld",indexPath.row + 1];
    cell.imageView.image = [UIImage imageNamed:imgName];
    cell.imageView.layer.cornerRadius = 18;
    cell.imageView.clipsToBounds = YES;
    cell.textLabel.text = @"测试";
    cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
    if (indexPath.row == 3) {
        UISwitch *swi = [UISwitch new];
        [swi sizeToFit];
        cell.accessoryView = swi;
    }
    return cell;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    EditViewController *con = [[EditViewController alloc] initWithStyle:UITableViewStyleGrouped];
    con.delegate = self;
    con.hidesBottomBarWhenPushed = YES;
    [self.navigationController pushViewController:con animated:YES];
}

- (void)inputString:(NSString *)text
{
    NSLog(@"输入了：%@",text);
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end
